// 多窗口例子，比如你登录后销毁登录窗口载入主窗口
package main

import (
	app "gitee.com/go_888/xcgui/xcgui/app"
	widget "gitee.com/go_888/xcgui/xcgui/widget"
	window "gitee.com/go_888/xcgui/xcgui/window"
	xcc "gitee.com/go_888/xcgui/xcgui/xcc"
)

var (
	a    *app.X结构_全局API
	w1   *window.Window
	w2   *window.Window
	btn1 *widget.X结构_按钮
	btn2 *widget.X结构_按钮
)

func main() {
	a = app.X创建(true)
	a.X启用DPI(true)
	a.X启用自动DPI(true)

	loadWindow1()

	a.X运行()
	a.X退出()
}

func loadWindow1() {
	w1 = window.X创建窗口(0, 0, 200, 200, "窗口1", 0, xcc.X窗口样式_默认样式)
	btn1 = widget.X创建按钮(50, 50, 100, 30, "载入窗口2", w1.X句柄)
	btn1.X事件_被单击1(onBnClick)
	w1.X显示(true)
}

func loadWindow2() {
	w2 = window.X创建窗口(0, 0, 300, 300, "窗口2", 0, xcc.X窗口样式_默认样式)
	btn2 = widget.X创建按钮(100, 100, 100, 30, "载入窗口1", w2.X句柄)
	btn2.X事件_被单击1(onBnClick)
	w2.X显示(true)
}

func onBnClick(hEle int, pbHandled *bool) int {
	switch hEle {
	case btn1.X句柄:
		*pbHandled = true // 把单击事件拦截了, 载入新窗口时这是必要的
		w1.X关闭()
		loadWindow2()
	case btn2.X句柄:
		*pbHandled = true // 把单击事件拦截了, 载入新窗口时这是必要的
		w2.X关闭()
		loadWindow1()
	}
	return 0
}
